﻿using System;
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Assets.Script
{
    public class AdvertisingSprite : MonoBehaviour, IPointerClickHandler
    {
        public Image showImg;
        public Text disText,nameText;
        public AdvertisingData m_data;

        PropType type;

        public void OnPointerClick(PointerEventData eventData)
        {
            StartCoroutine(PlayeVideo());
        }

        IEnumerator PlayeVideo()
        {
            UIManager.Ins.OpenUI(UIName.AdvertisingPanel);
            yield return new WaitForSeconds(5.5f);
            UIManager.Ins.CloseUI(UIName.AdvertisingPanel);
            MainPanelModel model = ModelManager.Ins.GetModel(MainPanelModel.m_name) as MainPanelModel;
            switch (type)
            {
                case PropType.magnet:
                    {
                        Debug.Log("恭喜您观看广告成功！！\r\n获取了吸取经验的道具\r\n效果是：自动吸取周围经验包10S ");
                        GameDataSprite.Ins.playerMagnet = 10;
                        model.RefurePlayerData(new PlayerData()
                        {
                            magnetTime = GameDataSprite.Ins.playerMagnet
                        });
                    }
                    break;
                case PropType.speed:
                    {
                        Debug.Log("恭喜您观看广告成功！！\r\n获取了加持速度的道具\r\n效果是：开局获取2倍移速持续10S ");
                        GameDataSprite.Ins.playerSpeed =10;
                        model.RefurePlayerData(new PlayerData()
                        {
                            addSpeedTime = GameDataSprite.Ins.playerSpeed
                        });
                    }
                    break;
                case PropType.level:
                    {
                        MessageCenter.Ins.BuredMess(MessId.RefureNowPlayerLevelData, 10);
                    }
                    break;
                case PropType.coins:
                    {
                        MessageCenter.Ins.BuredMess(MessId.RefureCurrencyData, new CurrencyData()
                        {
                            gold = 1500,
                            zuanshi =0 
                        });
                    }
                    break;
                default:
                    break;
            }
            MessageCenter.Ins.BuredMess(MessId.ConcealAdvertising, type);
        }

        public void RefureData(AdvertisingData data)
        {
            m_data = data;
            showImg.sprite = Resources.Load<Sprite>(m_data.bgIcon);
            disText.text = m_data.dis;
            nameText.text = m_data.name;
            type = (PropType)m_data.type;
        }
    }
}
